//
//  HomePageViewController.m
//  小说
//
//  Created by 魏忠海 on 2018/5/27.
//  Copyright © 2018年 WZH. All rights reserved.
//

#import "HomePageViewController.h"
#import "XSDataListViewController.h"

@interface HomePageViewController ()

/**
 默认初始次数Label
 */
@property (nonatomic, strong) UILabel *defuleLabel;

/**
 修改默认值输入框
 */
@property (nonatomic, strong) UITextField *defuleTextfield;

/**
 确认修改按钮
 */
@property (nonatomic, strong) UIButton *defuleButton;

/**
 循环次数
 */
@property (nonatomic, strong) UITextField *forTextfield;

/**
 开始查询按钮
 */
@property (nonatomic, strong) UIButton *queryButton;

/**
 查看历史记录
 */
@property (nonatomic, strong) UIButton *historyButton;

@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    [self configUI];
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma mark 初始化UI控件
- (void)initUI{
    self.defuleLabel    = [UILabel new];
    self.defuleTextfield= [UITextField new];
    self.defuleButton   = [UIButton new];
    self.forTextfield   = [UITextField new];
    self.queryButton    = [UIButton new];
    self.historyButton  = [UIButton new];
    [self.view addSubview:self.defuleLabel];
    [self.view addSubview:self.defuleTextfield];
    [self.view addSubview:self.defuleButton];
    [self.view addSubview:self.forTextfield];
    [self.view addSubview:self.queryButton];
    [self.view addSubview:self.historyButton];
    
    self.defuleLabel.text = @"15812";
    self.defuleTextfield.placeholder = @"可以修改默认开始的数值，建议不要修改";
    self.defuleTextfield.borderStyle = UITextBorderStyleRoundedRect;
    [self.defuleButton setTitle:@"确认修改默认开始的数值" forState:UIControlStateNormal];
    [self.defuleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.defuleButton addTarget:self action:@selector(defuleClick:) forControlEvents:UIControlEventTouchUpInside];
    self.forTextfield.placeholder = @"请输入开始循环的次数";
    self.forTextfield.borderStyle = UITextBorderStyleRoundedRect;
    [self.queryButton setTitle:@"开始查询相关数据" forState:UIControlStateNormal];
    [self.queryButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.queryButton.backgroundColor = [UIColor greenColor];
    [self.queryButton addTarget:self action:@selector(queryClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.historyButton setTitle:@"缓存的历史数据" forState:UIControlStateNormal];
    [self.historyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.historyButton addTarget:self action:@selector(historyClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.historyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.historyButton.layer.cornerRadius = 5;
    self.defuleButton.layer.cornerRadius = 5;
    self.historyButton.backgroundColor = [UIColor greenColor];
    self.defuleButton.backgroundColor = [UIColor greenColor];
    
}

#pragma mark 为UI控件添加约束
- (void)configUI{
    [self.defuleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.equalTo(self.mas_topLayoutGuide).mas_offset(20);
    }];
    [self.defuleTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.defuleLabel);
        make.left.mas_offset(20);
        make.height.mas_offset(30);
        make.top.equalTo(self.defuleLabel.mas_bottom).mas_offset(20);
    }];
    [self.defuleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.defuleTextfield);
        make.top.equalTo(self.defuleTextfield.mas_bottom).mas_offset(20);
    }];
    [self.forTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.equalTo(self.defuleButton);
        make.top.equalTo(self.defuleButton.mas_bottom).mas_offset(20);
    }];
    [self.queryButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.equalTo(self.forTextfield);
        make.top.equalTo(self.forTextfield.mas_bottom).mas_offset(20);
    }];
    [self.historyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerX.equalTo(self.queryButton);
        make.top.equalTo(self.queryButton.mas_bottom).mas_offset(20);
    }];
    
    
}

#pragma mark 开始查询按钮点击事件
- (void)queryClick:(UIButton *)sender{
    XSDataListViewController *vc = [XSDataListViewController new];
    vc.startNumber = self.defuleLabel.text;
    vc.forNumber = self.forTextfield.text;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 修改默认按钮点击事件
- (void)defuleClick:(UIButton *)sender{
    
}

#pragma mark 历史记录按钮点击事件
- (void)historyClick:(UIButton *)sender{
    XSDataListViewController *vc = [XSDataListViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
